package com.library.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.library.base.BaseController;
import com.library.base.R;
import com.library.domain.pojo.LendRecord;
import com.library.domain.pojo.Reader;
import com.library.service.ReaderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : 凉小天
 * @date : 2021/7/1 16:46
 */
@RestController
@RequestMapping("/reader")
public class ReaderController extends BaseController {

    @Resource
    private ReaderService readerService;

    /**
     * 分页查询所有数据
     */
    @GetMapping("/list")
    public R  selectAll (Page<Reader> page, Reader reader){
        return result(this.readerService.page(page,reader));
    }
    /**
     * 添加读者
     */

    @PostMapping("/add")
    public R addReader(@RequestBody Reader reader){
        return result(readerService.save(reader));
    }

    /**
     * 修改读者
     * @return
     */
    @PostMapping("update")
    public R updateReader(@RequestBody Reader reader){
        return result(readerService.updateById(reader));
    }
    /**
     * 根据编号删除批量删除读者
     */

    @GetMapping("/delete")
    public R deleteReader(@RequestParam List<String> ids){
        return result(readerService.removeByIds(ids));
    }
    /**
     * 重置密码
     */

    @PostMapping("/resetPwd")
    public R resetPwd(Reader reader){
        return result(readerService.updateById(reader));
    }
}